
const state = {
  list: [],
  total: 0,
  pageIndex: 1,
  pageSize: 10
}

const mutations = {
  SET_LIST: (state, list) => {
    state.list = [
      ...state.list,
      ...list
    ]
    const newArr = []
    const tmp = new Map()
    for (let i = 0; i < state.list.length; i++) {
      if (!tmp.get(state.list[i].accountId)) {
        tmp.set(state.list[i].accountId, 1)
        newArr.push(state.list[i])
      }
    }
    state.list = newArr
    state.total = state.list.length
  },
  DEL_LIST: (state, list) => {
    state.list = state.list.filter(item => {
      let isHas = false
      list.map(item1 => {
        if (item.accountId === item1.accountId) {
          isHas = true
        }
      })
      if (!isHas) return item
    })
  },
  RESET_LIST: (state) => {
    state.list = []
    state.total = 0
  }
}

const actions = {
  // 短信模版选择电工列表
  setSmsElectricianList({ commit }, list) {
    commit('SET_LIST', list)
  },
  // 短信模版删除电工列表
  delSmsElectricianList({ commit }, list) {
    commit('DEL_LIST', list)
  },
  // 短信模版清空电工列表
  resetSmsElectricianList({ commit }) {
    commit('RESET_LIST')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
